<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 在线影院订票系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
        }
        .login-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        .login-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem;
            text-align: center;
        }
        .login-form {
            padding: 2rem;
        }
        .form-control {
            border-radius: 10px;
            border: 2px solid #e9ecef;
            padding: 12px 15px;
        }
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        .btn-login {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 10px;
            padding: 12px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .alert {
            border-radius: 10px;
        }
        .forgot-password {
            color: #667eea;
            text-decoration: none;
        }
        .forgot-password:hover {
            color: #764ba2;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-5">
                <div class="login-container">
                    <div class="login-header">
                        <h2><i class="fas fa-film me-2"></i>影院订票系统</h2>
                        <p class="mb-0">欢迎登录</p>
                    </div>
                    
                    <div class="login-form">
                        <!-- 错误信息 -->
                        <c:if test="${not empty error}">
                            <div class="alert alert-danger" role="alert">
                                <i class="fas fa-exclamation-triangle me-2"></i>${error}
                            </div>
                        </c:if>
                        
                        <!-- 成功信息 -->
                        <c:if test="${not empty success}">
                            <div class="alert alert-success" role="alert">
                                <i class="fas fa-check-circle me-2"></i>${success}
                            </div>
                        </c:if>
                        
                        <form action="${pageContext.request.contextPath}/login" method="post" id="loginForm">
                            <div class="mb-3">
                                <label for="username" class="form-label">
                                    <i class="fas fa-user me-1"></i>用户名
                                </label>
                                <input type="text" class="form-control" id="username" name="username" 
                                       value="${username}" required placeholder="请输入用户名">
                            </div>
                            
                            <div class="mb-3">
                                <label for="password" class="form-label">
                                    <i class="fas fa-lock me-1"></i>密码
                                </label>
                                <input type="password" class="form-control" id="password" name="password" 
                                       required placeholder="请输入密码">
                            </div>
                            
                            <div class="mb-3">
                                <label for="phone" class="form-label">
                                    <i class="fas fa-phone me-1"></i>手机号
                                </label>
                                <input type="tel" class="form-control" id="phone" name="phone" 
                                       required placeholder="请输入手机号">
                            </div>
                            
                            <div class="d-grid mb-3">
                                <button type="submit" class="btn btn-primary btn-login">
                                    <i class="fas fa-sign-in-alt me-2"></i>登录
                                </button>
                            </div>
                            
                            <!-- 找回密码按钮 -->
                            <c:if test="${showForgotPassword}">
                                <div class="text-center mb-3">
                                    <a href="#" class="forgot-password" onclick="forgotPassword()">
                                        <i class="fas fa-key me-1"></i>忘记密码？
                                    </a>
                                </div>
                            </c:if>
                            
                            <div class="text-center">
                                <span class="text-muted">还没有账号？</span>
                                <a href="${pageContext.request.contextPath}/register" class="text-decoration-none">
                                    立即注册
                                </a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            // 表单验证
            $('#loginForm').on('submit', function(e) {
                var username = $('#username').val().trim();
                var password = $('#password').val().trim();
                var phone = $('#phone').val().trim();
                
                if (!username || !password || !phone) {
                    e.preventDefault();
                    alert('请填写所有必填项');
                    return false;
                }
                
                // 手机号格式验证
                var phoneRegex = /^1[3-9]\d{9}$/;
                if (!phoneRegex.test(phone)) {
                    e.preventDefault();
                    alert('请输入有效的手机号码');
                    return false;
                }
            });
        });
        
        function forgotPassword() {
            alert('找回密码功能暂未开放，请联系管理员');
        }
    </script>
</body>
</html>
